//
//  WWWelComeViewController.swift
//  SinWEiBo
//
//  Created by 胡良志 on 2018/3/24.
//  Copyright © 2018年 HuLiangZhi. All rights reserved.
//  登陆之后的欢迎页面

import UIKit
import SDWebImage
class WWWelComeViewController: UIViewController {

    override func viewDidAppear(_ animated: Bool) {
        super .viewDidAppear(animated)
        startAnimtion()
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = UIColor.white
        self.view.addSubview(iconImage)
        self.view.addSubview(WelcomeLabel)
        
        iconImage.snp.makeConstraints { (make) in
            make.centerX.equalTo(self.view)
            make.bottom.equalTo(self.view).offset(-120)
            make.size.equalTo(CGSize(width: 85, height: 85))
        }
        WelcomeLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(iconImage)
            make.top.equalTo(iconImage.snp.bottom).offset(20)
        }
        
        //加载网络图像
        let url = URL(string: (WWUserAccountViewModel.shared.userAccount?.avatar_large) ?? "")
        iconImage.sd_setImage(with: url, completed: nil)
        //设置圆角
        iconImage.layer.cornerRadius = 85 * 0.5
        iconImage.layer.masksToBounds = true
        
    }

    //用户头像
    private lazy var iconImage : UIImageView = UIImageView(image: #imageLiteral(resourceName: "avatar_default_big"))
    private lazy var WelcomeLabel : UILabel = {
        let label = UILabel()
        label.text = WWUserAccountViewModel.shared.userAccount?.name
        label.textColor = #colorLiteral(red: 0.5741485357, green: 0.5741624236, blue: 0.574154973, alpha: 1)
        label.font = UIFont.systemFont(ofSize: 14)
        label.alpha = 0
        return label
    }()

    //动画
    private func startAnimtion (){
        let offsetY = -(UIScreen.main.bounds.height - 120 - iconImage.bounds.height)
        self.iconImage.snp.updateConstraints { (make) in
            make.bottom.equalTo(self.view).offset(offsetY)
        }
        
        UIView .animate(withDuration: 1.5, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 5, options: UIViewAnimationOptions(rawValue: 0), animations: {
            //让约束动画生效必须调用
            self.view.layoutIfNeeded()
        }) { (fisished) in

            UIView .animate(withDuration: 0.5, animations: {
                self.WelcomeLabel.alpha = 1
            }, completion: { (fisished) in
                //动画完成之后切换跟控制器
                NotificationCenter.default.post(name: NSNotification.Name(kchoseRootViewController), object: nil)
            })

        }
    }
 
    
    
    
    
}
















